package college.util;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

import org.apache.poi.hssf.usermodel.HSSFCell;
import org.apache.poi.hssf.usermodel.HSSFRow;
import org.apache.poi.hssf.usermodel.HSSFSheet;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;


public class ExcelFileReader {
	public static List  getExcelData(String fileName) {
		Object data[][] = null;
		HSSFWorkbook book = null;
		List sheetData = null; 
		try {
			FileInputStream inputStream = new FileInputStream(fileName);
			try {
				book = new HSSFWorkbook(inputStream);
				HSSFSheet sheet = book.getSheetAt(0);
				sheetData = new ArrayList(); 
				Iterator rowIterator = sheet.rowIterator();
				while(rowIterator.hasNext()) {
					HSSFRow row = (HSSFRow)rowIterator.next();
					List rowData = new ArrayList(); 
					Iterator cellIterator = row.cellIterator();
					while(cellIterator.hasNext()) {
						HSSFCell cell = (HSSFCell)cellIterator.next();
						rowData.add(cell.toString());
					}
					sheetData.add(rowData);
				}
			} catch (IOException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		
			
		} catch (FileNotFoundException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
		return sheetData;
	}
}
